let id = 0;
class Dep {
  constructor(){
    this.id = ++id;
    this.subs = [];
  }
  //收集
  depend(){
    // 让watcher可以存放dep
    // 双向记忆
    // this.subs.push(Dep.target)
    Dep.target.addDep(this)
  }

  addSub(watcher){
    this.subs.push(watcher)
  }
  // 更新
  notify(){
    this.subs.forEach(watcher => {
      watcher.update();
    })
  }
}
Dep.target = null;
let stack = [];
// 添加wacher
export function pushTarget(watcher){
 Dep.target = watcher;
 stack.push(watcher);
}
// 取消wacher
export function popTarget(watcher){
  // 解析完一个wancher就删除一个watcher
  stack.pop();
  Dep.target = stack[stack.length - 1]; // 获取到你前面的一个watcher
}

export default Dep;